#include "store/store.h"
#include "bytes.h"
#include "util.h"
#include <stdio.h>

#include <string.h>

int main(int c,char **v){
   
	struct store_chunk chunk;
	chunk_initial(&chunk,"file");
	struct buffer *buff=buffer_new(chunk.bf_hdl);
	ready_to_read(buff);
	barray_to_bytes(buff,"hello world",11);
	
	save_key(buff,"mengnan",7,&chunk);
	
	struct buffer *buff2=buffer_new(chunk.bf_hdl);
	int res=query_key(buff2,"mengnan",7,&chunk);
	if(!res){
		printf("query value is %s\n",buff2->data);
	}
	take_key(NULL,"mengnan",7,&chunk);
	struct buffer *buff3=buffer_new(chunk.bf_hdl);
	res=query_key(buff3,"mengnan",7,&chunk);
	printf("requery  ret is %d value is %s\n",res,buff3->data);
/*	
	struct buffer *buff=buffer_new(chunk.bf_hdl);
	ready_to_read(buff);
	
	int is_big=is_big_cpu();
	buffer_begin_batch(buff,2);
	(buff->data)[2]='1';
	(buff->data)[3]='2';
	buff->index=4;
	buffer_end_batch(buff,2,is_big);

	save_stream(buff,&chunk);
	forc_sync(&chunk);

	struct buffer *p;
	query_stream(&p,&chunk);
	ready_to_write(p);
	printf("content %s\n index %d limit %d",p->data,p->index,p->limit);
*/
	
	chunk_release(&chunk);
/*
	struct bufferFactory *bf=bufferFactory_build(8,4);
	struct buffer *buffer=buffer_new(bf);
	ready_to_read(buffer);
	
	int is_big=is_big_cpu();
	printf("is big-endian %d\n",is_big);
	short_to_bytes(buffer,2,is_big);

	ready_to_write(buffer);
	short value;
	bytes_to_short(buffer,&value,is_big);
printf("read bytes to short %d\n",value);
	bufferFactory_release(bf);
*/
	return 0;
}
